import pymysql
import datetime

if __name__ == "__main__":
    conn = pymysql.connect(
        host="127.0.0.1",
        user="haojg",
        password="haojg",
        database="stocks",
        charset="utf8",
    )

    cursor = conn.cursor()

    insert_sql = (
        "INSERT INTO t_stock_k_minute_data ("
        + "sd_date,sd_date_time,sd_code,sd_symbol,sd_name,"
        + "sd_open,sd_high,sd_low,sd_close,sd_volume,"
        + "sd_amount,sd_adjust_flag,sd_data_type,create_time,update_time) "
        + "VALUES ("
        + "%s,%s,%s,%s,%s,"
        + "%s,%s,%s,%s,%s,"
        + "%s,%s,%s,%s,%s) ;"
    )

    try:
        cursor.executemany(
            insert_sql,
            (
                (
                    "1",
                    "1",
                    "1",
                    "1",
                    "1",
                    "1",
                    "1",
                    "1",
                    "1",
                    "1",
                    "1",
                    "1",
                    "1",
                    datetime.datetime.now(),
                    datetime.datetime.now(),
                ),
            ),
        )
        conn.commit()
    except Exception as e:
        print("error = ", e)
        conn.rollback()

    cursor.close()
    conn.close()

    query_sql = "select * from t_stock_k_minute_data tskmd "

    print("end ok")
